home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Games / Pentominoes 2.0 / Shell ƒ / pict utilities.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-15  |  1.7 KB  |  54 lines  |  [TEXT/MMCC]

  1. #include "pict utilities.h"
  2.  
  3. PicHandle DrawThePicture(PicHandle thePict, short whichPict, short x, short y)
  4. /* a standard routine for loading a picture (if necessary) and then drawing it */
  5. {
  6.     Rect            temp;
  7.     
  8.     if (thePict==0L)        /* get it if it doesn't exist */
  9.         thePict=(PicHandle)GetPicture(whichPict);
  10.     
  11.     HLock((Handle)thePict);        /* lock it down for dereferencing to get picture bounds */
  12.     temp.top=y;
  13.     temp.left=x;
  14.     temp.bottom=temp.top+(**thePict).picFrame.bottom-(**thePict).picFrame.top;
  15.     temp.right=temp.left+(**thePict).picFrame.right-(**thePict).picFrame.left;
  16.     DrawPicture(thePict, &temp);    /* draw picture at (x,y) */
  17.     HUnlock((Handle)thePict);        /* unlock for better memory management */
  18.     return thePict;
  19. }
  20.  
  21. PicHandle ReleaseThePict(PicHandle thePict)
  22. {
  23.     if (thePict!=0L)    /* if exists, release it */
  24.         ReleaseResource((Handle)thePict);
  25.     return 0L;
  26. }
  27.  
  28. Boolean DrawPictureCentered(PicHandle thePict, Rect boundsRect, Rect *destRect)
  29. /* returns TRUE if picture was drawn successfully */
  30. /* returns FALSE if picture was larger than boundsRect or PicHandle was NULL */
  31. {
  32.     Rect            temp;
  33.     
  34.     if (thePict==0L)
  35.         return FALSE;
  36.     
  37.     HLock((Handle)thePict);
  38.     temp.top=boundsRect.top;
  39.     temp.left=boundsRect.left;
  40.     temp.bottom=temp.top+(**thePict).picFrame.bottom-(**thePict).picFrame.top;
  41.     temp.right=temp.left+(**thePict).picFrame.right-(**thePict).picFrame.left;
  42.     HUnlock((Handle)thePict);
  43.     if ((temp.bottom-temp.top>boundsRect.bottom-boundsRect.top) ||
  44.         (temp.right-temp.left>boundsRect.right-boundsRect.left))
  45.         return FALSE;
  46.     
  47.     OffsetRect(&temp, (boundsRect.right-boundsRect.left-(temp.right-temp.left))/2,
  48.         (boundsRect.bottom-boundsRect.top-(temp.bottom-temp.top))/2);
  49.     DrawPicture(thePict, &temp);
  50.     *destRect=temp;
  51.     
  52.     return TRUE;
  53. }
  54.